$('#longurl').on('click',
function() {
	layer.tips("此内请填写URL地址", "#longurl", {
		tipsMore: true,
		tips: [1, "#3366FF"],
		time: 5000
	});
});

var api_host = 'https://api.sumt.cn/';
         //短网址还原
            $('#url_long').click(function() {
            	var url = $('#longurl').val();
            	if (url == '') {
            		layer.msg('请填写短网址后再还原哦', {
            		    shade: [0.8, '#393D49'],
                        shadeClose:true,
            			icon: 7,
            			anim: 6
            		});
            		return false;
            	}
            	$.ajax({
            		type: "GET",
            		url: api_host+"/api/restore.php",
            		dataType: "json",
            		async: true,
            		scriptCharset: 'GBK',
            		data: {'url': url},
            		beforeSend: function() {
            			layer.msg('还原中，请您稍候...', {
            				icon: 16,
            				anim: 3,
            				shade: 0.01,
            				time: 2000000
            			});
            			$('#url_long').attr('disabled', true).html('请您稍后...');
            		},
            		success: function(data) {
            			if (data.code == 200) {
            				layer.confirm('<div class="form-group"><div class="input-group has-success"><div class="input-group-addon">短网址</div><input type="text" value="' + data.url_short + '" class="form-control" readonly="readonly"></div></div><div class="form-group"><div class="input-group has-success"><div class="input-group-addon">长网址</div><input type="text" value="' + data.url_long + '" class="form-control" readonly="readonly"><span class="input-group-btn" id="btn" data-clipboard-text="' + data.url_long + '"><a data-toggle="modal" class="btn btn-warning"><i class="glyphicon glyphicon-duplicate"></i></a></span></div></div>', {
                    		    title: '还原网址结果！',
                                skin: 'layui-layer-molv',
                                offset:'110px',
                                closeBtn:0,
            				});
            			} else {
            				layer.msg('' + data.msg + '', {
            					icon: 2,
            					anim: 6
            				});
            			}
            			$('#url_long').attr('disabled', false).html('还原网址');
            		},
            		error: function() {
            			layer.msg('抱歉，服务器错误！', {
            				icon: 2,
            				anim: 6
            			});
            			$('#url_long').attr('disabled', false).html('还原网址');
            		}
            	});
            });        
            
          function sweet() {
                $.getJSON('https://api.uomg.com/api/rand.qinghua?format=json', function(json) {
                    layer.alert('<blockquote class="layui-elem-quote">'+json.content+'</blockquote>', {
                        skin: 'layui-layer-molv',
                        shade: [0.8, '#393D49'],
                        btn: ['复制','刷新'],
                        title: '情话&污话',
                        offset:'120px',
                        anim: 1,
                        yes: function () {
                            var clipboard = new Clipboard('.layui-layer-btn0', {
                                text: function() {
                                    return json.content
                                }
                            });
							clipboard.on('success', function(e) {
							    layer.tips('已复制到剪切板', ".layui-layer-btn0", {
							        tips: [1, "#2E8B57"]
							       });
							});
                        },
                        btn2: function() {
                            $('#sweet').click();
                        },
                    });
                    $('#sweet').text('再来一句');
                });
            };          
            function sjmn() {
                $.getJSON('https://api.uomg.com/api/rand.img2?sort=美女&format=json', function(json) {
            	    layer.open({
            	        type:1,
            	        title:false,
            	        offset:'120px',
            	        closeBtn:2,
                        shade: [0.8, '#393D49'],
            	        skin: 'layui-layer-rim',
            	        content: '<img src="'+ json.imgurl +'" title="随机竖版图片" style="width:234px;">',
            	    });
            	    $('#sjmn').text('再来一张');
            	});
            };
                                     
var btn = document.getElementById('btn');
var clipboard = new Clipboard("#btn");
clipboard.on("success", function(e) {
alert('复制链接成功！');
});
clipboard.on("error", function(e) {
     layer.msg('复制失败，请长按后手动复制！',{icon:5});
});
$(function(){
	$("#haohaofh").css("display","none");//隐藏输出框
	$("#sc").click(function(){
	$("#haohaofh").css("display","inherit");//执行后输出
	});
});